package com.tuo51.manager.controller;


import com.tuo51.evaluate.repositories.MailRecordRepository;
import com.tuo51.evaluate.service.EvaluateV2ExportService;
import com.tuo51.foudation.model.MemVerificationCache;
import com.tuo51.foudation.model.StatusResponse;
import com.tuo51.foudation.query.base.PagerQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.tuo51.foudation.constant.RequestConstant.TICKET;

@RestController
@RequestMapping("/mapi/export_records")
@Api(value = "/mapi/export_records", tags = "OP - 导出记录")
public class MAPIMailRecordsController {
    @Autowired
    private MemVerificationCache cache;

    @Autowired
    private MailRecordRepository mailRecordRepository;

    @Autowired
    private EvaluateV2ExportService exportService;


    @ApiOperation(value = "邮件记录",httpMethod = "GET")
    @GetMapping(value = "/mail_records")
    public StatusResponse newsList(@RequestHeader(TICKET) String ticket,
                                   PagerQuery pagerQuery){
        if (pagerQuery.getPageSize() <= 0){
            pagerQuery.setPageSize(10);
        }

        String staffId = cache.getStaffId(ticket);

        PageRequest pageRequest = PageRequest.of(pagerQuery.getPageNum(), pagerQuery.getPageSize());

        return StatusResponse.success(mailRecordRepository.findAllByOrderByCreatedDesc(pageRequest));
    }

}
